package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借一本书");
        System.out.println("请输入你要借的书名");
        Scanner sca = new Scanner(System.in);
        String bookName = sca.nextLine();

        int currentSize = bookList.getUsedSize();
        for(int i = 0; i < currentSize; i++){
            Book book = bookList.getBook(i);
            if(book.getName().equals(bookName)){
                if(!book.getLend()){
                bookList.getBook(i).setLend(true);
                System.out.println("借阅成功!");
                return;
                }else {
                    System.out.println("此书已被借阅");
                    return;
                }
            }
        }
        System.out.println("不存在你要借的书");
    }
}
